package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"strconv"
	"Fblog/util"
)

//图文上传
type EditorController struct {
	beego.Controller
}

// @router /uploadFile [post]
func (this *EditorController) Post() {
	// 获取表单信息
	//uname := this.Input().Get("uname")
	//pwd := this.Input().Get("pwd")
	//autoLogin := this.Input().Get("autoLogin") == "on"

	f, h, err := this.GetFile("imgFile")
	defer f.Close()
	addr := "static/upload/" + util.GetGuid() + h.Filename
	err = this.SaveToFile("imgFile", addr)
	if err != nil {
		logs.Debug(err)
	}

	httppath := this.Ctx.Input.Site() + ":" + strconv.Itoa(this.Ctx.Input.Port())

	this.Data["json"] = UploadRet{Url:httppath + "/" + addr, Error:0, Message:"上传成功"}

	this.ServeJSON()

	return
}

//func (c *EditorController)Get() {
//	c.TplName = "default.html"
//}

type UploadRet struct {
	Url     string `json:"url"`
	Error   int `json:"error"`
	Message string `json:"message"`
}